<!--
 * @describe: 描述
 * @Author: superDragon
 * @Date: 2019-09-10 15:39:31
 * @LastEditors: superDragon
 * @LastEditTime: 2019-09-12 09:43:46
 -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>encode</title>
  </head>
  <script>
    // 接受父页面发来的信息
    window.addEventListener('message', function(event) {
      var data = event.data
      switch (data.cmd) {
        case 'getJson':
          try {
            let raw2Protocol = new Function('"use strict";return (' + data.code + ')')()
            let result = raw2Protocol(data.params)
            window.parent.postMessage(
              {
                cmd: 'returnJson',
                params: result
              },
              '*'
            )
            break
          } catch (error) {
            alert(error)
          }
      }
    })
  </script>
  <body></body>
</html>
